<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: Roomer::Tools
  
    &mdash; Documentation by YARD 0.7.2
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '..';
  if (relpath != '') relpath += '/';
</script>

  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (T)</a> &raquo; 
    <span class='title'><span class='object_link'><a href="../Roomer.html" title="Roomer (module)">Roomer</a></span></span>
     &raquo; 
    <span class="title">Tools</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a id="class_list_link" href="#">Class List</a>
  
    <a id="method_list_link" href="#">Method List</a>
  
    <a id="file_list_link" href="#">File List</a>
  
</div>
      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: Roomer::Tools
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Roomer::Tools</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/roomer/tools.rb</dd>
  
</dl>
<div class="clear"></div>






  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#create_schema-class_method" title="create_schema (class method)">+ (Object) <strong>create_schema</strong>(schema_name) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Creates a schema in PostgreSQL.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#drop_schema-class_method" title="drop_schema (class method)">+ (Object) <strong>drop_schema</strong>(schema_name) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Drops a schema and all it’s objects (Cascades).</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#ensure_prefix-class_method" title="ensure_prefix (class method)">+ (Object) <strong>ensure_prefix</strong>(prefix, &amp;block) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Ensures the same ActiveRecord::Base#table_name_prefix for all the  models
executed in the block.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#ensure_schema_migrations-class_method" title="ensure_schema_migrations (class method)">+ (Object) <strong>ensure_schema_migrations</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Ensures schema_migrations table exists and creates otherwise.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#ensuring_schema-class_method" title="ensuring_schema (class method)">+ (Object) <strong>ensuring_schema</strong>(schema_name, &amp;block) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Ensures the schema and schema_migrations exist(creates them otherwise)  and
executes the code block.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#schemas-class_method" title="schemas (class method)">+ (Array) <strong>schemas</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>lists the schemas available.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="create_schema-class_method">
  
    + (<tt>Object</tt>) <strong>create_schema</strong>(schema_name) 
  

  
</p><div class="docstring">
  <div class="discussion">
    
<p>Creates a schema in PostgreSQL</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>schema_name</span>
      
      
        <span class='type'>(<tt>#to_s</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>declaring the name of the schema</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


7
8
9</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 7</span>

<span class='def def kw'>def</span> <span class='create_schema identifier id'>create_schema</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='rparen token'>)</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='connection identifier id'>connection</span><span class='dot token'>.</span><span class='execute identifier id'>execute</span> <span class='dstring node'>&quot;CREATE SCHEMA #{schema_name.to_s}&quot;</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="drop_schema-class_method">
  
    + (<tt>Object</tt>) <strong>drop_schema</strong>(schema_name) 
  

  
</p><div class="docstring">
  <div class="discussion">
    
<p>Drops a schema and all it’s objects (Cascades)</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>schema_name</span>
      
      
        <span class='type'>(<tt>#to_s</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>declaring the name of the schema to drop</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


13
14
15</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 13</span>

<span class='def def kw'>def</span> <span class='drop_schema identifier id'>drop_schema</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='rparen token'>)</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='connection identifier id'>connection</span><span class='dot token'>.</span><span class='execute identifier id'>execute</span><span class='lparen token'>(</span><span class='dstring node'>&quot;DROP SCHEMA IF EXISTS #{name.to_s} CASCADE&quot;</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="ensure_prefix-class_method">
  
    + (<tt>Object</tt>) <strong>ensure_prefix</strong>(prefix, &amp;block) 
  

  
</p><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong> 
    <div class='inline'>
<p>All the Models will have the same prefix, caution is advised</p>
</div>
  </div>


<p>Ensures the same ActiveRecord::Base#table_name_prefix for all the  models
executed in the block</p>


  </div>
</div>
<div class="tags">
  
  <div class="examples">
    <h3>Examples:</h3>
    
      <h4><div class='inline'></div></h4>
      <pre class="example code"><span class='ensure_prefix identifier id'>ensure_prefix</span><span class='lparen token'>(</span><span class='symbol val'>:global</span><span class='rparen token'>)</span> <span class='do do kw'>do</span>
   <span class='Person constant id'>Person</span><span class='dot token'>.</span><span class='find identifier id'>find</span><span class='lparen token'>(</span><span class='integer val'>1</span><span class='rparen token'>)</span>  <span class='comment val'># =&gt; will execute &quot;SELECT id FROM 'global.person'&quot;</span>
<span class='end end kw'>end</span>
</pre>
    
  </div>
<h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>A</span>
      
      
        <span class='type'>(<tt>#to_s</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>Symbol declaring the table name prefix</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>code</span>
      
      
        <span class='type'>(<tt>#call</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>to execute</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


52
53
54
55
56</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 52</span>

<span class='def def kw'>def</span> <span class='ensure_prefix identifier id'>ensure_prefix</span><span class='lparen token'>(</span><span class='prefix identifier id'>prefix</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='block identifier id'>block</span><span class='rparen token'>)</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='table_name_prefix identifier id'>table_name_prefix</span> <span class='assign token'>=</span> <span class='dstring node'>&quot;#{prefix.to_s}#{Roomer.schema_seperator}&quot;</span>
  <span class='yield yield kw'>yield</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='table_name_prefix identifier id'>table_name_prefix</span> <span class='assign token'>=</span> <span class='old_prefix identifier id'>old_prefix</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="ensure_schema_migrations-class_method">
  
    + (<tt>Object</tt>) <strong>ensure_schema_migrations</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    
<p>Ensures schema_migrations table exists and creates otherwise</p>


  </div>
</div>
<div class="tags">
  
  <h3>See Also:</h3>
  <ul class="see">
    
      <li>ActiveRecord::Base.connection#initialize_schema_migrations_table</li>
    
  </ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


60
61
62</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 60</span>

<span class='def def kw'>def</span> <span class='ensure_schema_migrations identifier id'>ensure_schema_migrations</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='connection identifier id'>connection</span><span class='dot token'>.</span><span class='initialize_schema_migrations_table identifier id'>initialize_schema_migrations_table</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="ensuring_schema-class_method">
  
    + (<tt>Object</tt>) <strong>ensuring_schema</strong>(schema_name, &amp;block) 
  

  
</p><div class="docstring">
  <div class="discussion">
    
<p>Ensures the schema and schema_migrations exist(creates them otherwise)  and
executes the code block</p>


  </div>
</div>
<div class="tags">
  
  <div class="examples">
    <h3>Examples:</h3>
    
      <h4><div class='inline'></div></h4>
      <pre class="example code"><span class='ensuring_schema identifier id'>ensuring_schema</span><span class='lparen token'>(</span><span class='symbol val'>:global</span><span class='rparen token'>)</span> <span class='do do kw'>do</span>
   <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Migrator constant id'>Migrator</span><span class='dot token'>.</span><span class='migrate identifier id'>migrate</span><span class='lparen token'>(</span><span class='string val'>'/db/migrate'</span><span class='comma token'>,</span> <span class='string val'>'20110812012536'</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    
  </div>
<h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>schema_name</span>
      
      
        <span class='type'>(<tt>#to_s</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>declaring name to ensure</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>&amp;block</span>
      
      
        <span class='type'>(<tt>#call</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>code to execute</p>
</div>
      
    </li>
  
</ul>
<h3>Raises:</h3>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>ArgumentError</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


31
32
33
34
35
36
37
38
39
40</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 31</span>

<span class='def def kw'>def</span> <span class='ensuring_schema identifier id'>ensuring_schema</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='block identifier id'>block</span><span class='rparen token'>)</span>
  <span class='raise identifier id'>raise</span> <span class='ArgumentError constant id'>ArgumentError</span><span class='dot token'>.</span><span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='string val'>&quot;schema_name not present&quot;</span><span class='rparen token'>)</span> <span class='unless unless_mod kw'>unless</span> <span class='schema_name identifier id'>schema_name</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Migration constant id'>Migration</span><span class='dot token'>.</span><span class='verbose identifier id'>verbose</span> <span class='assign token'>=</span> <span class='ENV constant id'>ENV</span><span class='lbrack token'>[</span><span class='string val'>&quot;VERBOSE&quot;</span><span class='rbrack token'>]</span> <span class='question op'>?</span> <span class='ENV constant id'>ENV</span><span class='lbrack token'>[</span><span class='string val'>&quot;VERBOSE&quot;</span><span class='rbrack token'>]</span> <span class='eq op'>==</span> <span class='string val'>&quot;true&quot;</span> <span class='colon op'>:</span> <span class='true true kw'>true</span>
  <span class='create_schema identifier id'>create_schema</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='rparen token'>)</span> <span class='unless unless_mod kw'>unless</span> <span class='schemas identifier id'>schemas</span><span class='dot token'>.</span><span class='include? fid id'>include?</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='rparen token'>)</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='table_name_prefix identifier id'>table_name_prefix</span> <span class='assign token'>=</span> <span class='dstring node'>&quot;#{schema_name.to_s}#{Roomer.schema_seperator.to_s}&quot;</span>
  <span class='ensure_prefix identifier id'>ensure_prefix</span><span class='lparen token'>(</span><span class='schema_name identifier id'>schema_name</span><span class='rparen token'>)</span> <span class='do do kw'>do</span>
    <span class='ensure_schema_migrations identifier id'>ensure_schema_migrations</span>
    <span class='yield yield kw'>yield</span>
  <span class='end end kw'>end</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="schemas-class_method">
  
    + (<tt>Array</tt>) <strong>schemas</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    
<p>lists the schemas available</p>


  </div>
</div>
<div class="tags">
  <h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>list of schemas</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


19
20
21</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/roomer/tools.rb', line 19</span>

<span class='def def kw'>def</span> <span class='schemas identifier id'>schemas</span>
  <span class='ActiveRecord constant id'>ActiveRecord</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='connection identifier id'>connection</span><span class='dot token'>.</span><span class='query identifier id'>query</span><span class='lparen token'>(</span><span class='string val'>&quot;SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*'&quot;</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='flatten identifier id'>flatten</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Fri Aug 12 10:39:13 2011 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.7.2 (ruby-1.8.7).
</div>

  </body>
</html>